// const ENV = process.env.NODE_ENV
import { getToken } from "@/utils/storage";

export const generatedColumns = (vm, demo) => {
  return [
    {
      title: "企业名称",
      key: "name",
      align: "center"
    },
    {
      title: "城市",
      key: "cityName",
      align: "center",
      width: 90
    },
    {
      title: "企业地址",
      key: "address",
      align: "center"
    },
    {
      title: "联系人",
      key: "contactName",
      width: 100,
      align: "center"
    },
    {
      title: "联系电话",
      key: "contactPhone",
      width: 120,
      align: "center"
    },
    {
      title: "创建时间",
      align: "center",
      width: 120,
      render: (h, params) =>
        h("span", vm.moment(params.row.createdAt).format("YYYY-MM-DD"))
    },
    {
      title: "操作",
      align: "center",
      width: 260,
      render: (h, params) => {
        return h("div", [
          h(
            "Button",
            {
              props: {
                type: "primary",
                size: "small",
                disabled: demo
              },
              style: {
                marginRight: "5px"
              },
              on: {
                click: () => {
                  const row = { ...params.row };
                  vm.rowClick(row);
                }
              }
            },
            "企业设置"
          ),

          h(
            "Poptip",
            {
              props: {
                confirm: true,
                title: "您确定要删除这条数据吗?",
                transfer: true,
                cancelText: "取消"
              },
              on: {
                "on-ok": () => {
                  const row = { ...params.row };
                  vm.handleDelete(row);
                }
              }
            },
            [
              h(
                "Button",
                {
                  style: {
                    marginRight: "5px"
                  },
                  props: {
                    type: "error",
                    size: "small",
                    disabled: demo || params.row.name === "长沙平和堂五一广场店"
                  }
                },
                "删除"
              )
            ]
          ),

          h(
            "Button",
            {
              props: {
                type: "error",
                size: "small",
                disabled: demo
              },
              on: {
                click: () => {
                  const { row } = params;
                  const { transformerStructure, id } = row;
                  if (transformerStructure) {
                    // const path = window.location.origin + "/power"
                    // window.location.replace(path)
                    let urlOnline = `http://pht.bjsdzk.com?token=${getToken()}&companyId=${
                      row.id
                    }`;
                    window.open(urlOnline, "_blank");
                  } else {
                    vm.SET_COMPANYID(id);
                    vm.$router.push("/datacenter");
                  }
                }
              }
            },
            "进入企业"
          )
        ]);
      }
    }
  ];
};
